package com.example.city_home_app.Activity;

import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.WindowManager;

import com.example.city_home_app.Bean.Down_MsgCencter;
import com.example.city_home_app.Model.ApiModel;
import com.example.city_home_app.R;
import com.example.city_home_app.RecyclerViewAdapter.Adapter_MsgCenter;
import com.example.city_home_app.RecyclerViewAdapter.Adapter_NewsReply;
import com.example.city_home_app.RetrofitListener;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class MessageCenterActivity extends BaseActivity {
    @BindView(R.id.toolbar_messagecenter)
    Toolbar toolbarMessagecenter;
    @BindView(R.id.rec_msgcenter)
    RecyclerView recMsgcenter;

    private ApiModel model = new ApiModel();
    private Adapter_MsgCenter adapter_msgCenter;

    private RetrofitListener<List<Down_MsgCencter>> listRetrofitListener = new RetrofitListener<List<Down_MsgCencter>>() {
        @Override
        public void onResponse(List<Down_MsgCencter> listener) {
            adapter_msgCenter.setList(listener);
            adapter_msgCenter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {

        }
    };

    @Override
    protected int getContentLayoutId() {
        return R.layout.activity_messagecenter;
    }

    @Override
    protected void initViews() {
        super.initViews();
        ButterKnife.bind(this);
        showToast();

        recMsgcenter = (RecyclerView)findViewById(R.id.rec_msgcenter);
        LinearLayoutManager layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recMsgcenter.setLayoutManager(layoutManager);
        adapter_msgCenter = new Adapter_MsgCenter(this);
        recMsgcenter.setAdapter(adapter_msgCenter);
        recMsgcenter.setItemAnimator(new DefaultItemAnimator());
    }

    @Override
    protected void initData() {
        super.initData();
    }

    private void showToast() {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        toolbarMessagecenter = (Toolbar) findViewById(R.id.toolbar_messagecenter);
        setSupportActionBar(toolbarMessagecenter);
        toolbarMessagecenter.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

    }

    @Override
    protected void onResume() {
        super.onResume();
        model.getmessagelist(BaseActivity.getUserinfo().getUserid(),listRetrofitListener);
    }
}
